﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Linq.Expressions;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.Linq;
using System.Data.SqlClient;
using System.IO;
namespace Giao_dien_2.FormCT
{
    public partial class FormDangNhap : DevExpress.XtraEditors.XtraForm
    {
        public FormDangNhap()
        {
            InitializeComponent();
        }
        DBGiaoNhan giaonhan = new DBGiaoNhan();
        bool dongchuongtrinh = true;
        public void clean()
        {
            txt_tentruycap.Text = "";
            txt_matkhau.Text = "";
            txt_tentruycap.Focus();
        }

        private void btn_Huy_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }


        private void btn_dangnhap_Click(object sender, EventArgs e)
        {
            DBGiaoNhan giaonhan = new DBGiaoNhan();
            try
            {

                NHANVIENHC nvhc = giaonhan.NHANVIENHCs.Single(p => p.MaNVHC == txt_tentruycap.Text);
                if (nvhc.MatKhau == txt_matkhau.Text)
                {
                    MessageBox.Show("Đăng nhập thành công");

                    foreach (Giaodien f in Application.OpenForms)
                    {

                        f.Manguoidung = txt_tentruycap.Text;
                        dongchuongtrinh = false;
                        this.Close();
                        break;
                    }


                }
                else
                {
                    MessageBox.Show("Sai Mật Khẩu", "Lỗi");
                    clean();
                }
            }
            catch
            {
                MessageBox.Show("Không Tồn Tại Tài Khoản", "Lỗi");
                clean();
            }

        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            if (dongchuongtrinh)
                Application.Exit();
        }

        private void FormDangNhap_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (dongchuongtrinh)
                Application.Exit();
        }







    }
}